#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
 
 
 
inline void File2String(vector<string> &record, const string& line, char delimiter)
{
    int linepos=0;
    char c;
    int linemax=line.length();
    string curstring;
    record.clear();
    while(linepos<linemax)
    {
        c = line[linepos];
        if(isdigit(c)||c=='.'){
            curstring+=c;
        }
        else if(c==delimiter&&curstring.size()){
            record.push_back(curstring);
            curstring="";
        }
        ++linepos;
    }
    if(curstring.size())
        record.push_back(curstring);
    return;
}

int  ReadCsvTableData(string &file, Table_t &table)
{
    ifstream        in(file);
    string          line;
    vector<string>  row;
	vector<double>	b;

    if(in.fail()){
        printf("**- Warning: can not read file %s\n",file.c_str());
    }return 0;

    while(getline(in, line) && in.good()){
        File2String(row, line, ',');  //把line里的单元格数字字符提取出来，“,”为单元格分隔符
        for(int i=0, leng=row.size(); i<leng; i++){
            b.push_back(row[i]);
        }
        a.push_back(b);
        b.clear();
    }
}
void read()
{
    vector<string> row;
    string line;
    string filename;
    ifstream in("test5000.csv");  
    if (in.fail())  { cout << "File not found" <<endl; return ; } 
    while(getline(in, line)  && in.good() )
    {
        File2String(row, line, ',');  //把line里的单元格数字字符提取出来，“,”为单元格分隔符
        for(int i=0, leng=row.size(); i<leng; i++){
            b.push_back(string_to_double(row[i]));
        }
        a.push_back(b);
        b.clear();
    }
    in.close();
    return ;
}
 
 
inline double string_to_double(string str){
    int i=0,len=str.length();
    double sum=0;
    while(i<len){
        if(str[i]=='.') break;
        sum=sum*10+str[i]-'0';
        ++i;
    }
    ++i;
    double t=1,d=1;
    while(i<len){
        d*=0.1;
        t=str[i]-'0';
        sum+=t*d;
        ++i;
    }
    return sum;
}

int main(){
    read();
    printf("total numbers of people: %d\n",a.size());
    cout<<"top 5dims of person 1:"<<endl;
    for(int i=0;i<=4;i++)
        cout<<a[0][i]<<" ";
    return 0;
}